home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 3 / Info_Mac_1994-01.iso / Development / Source / MultiSession 1.04 Source / Core 27⁄June⁄1993 / CAboutWindow.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-05-16  |  5.1 KB  |  184 lines  |  [TEXT/KAHL]

  1. /* CAboutWindow.c */
  2.  
  3. #include "CAboutWindow.h"
  4. #include "EventLoop.h"
  5. #include "Memory.h"
  6. #include "CMyApplication.h"
  7. #include "MenuController.h"
  8.  
  9.  
  10. #define ApplicationVersionStringID (0x00800003)
  11. #define AboutWindowLocationID (0x00800001)
  12. #define ApplicationVersionLocationID (0x00800003)
  13. #define PictureLocationID (0x00800004)
  14. #define ShowDelay (60*5)
  15. #define PictureID 128
  16.  
  17. #define DevelopmentRelease (0x20)
  18. #define AlphaRelease (0x40)
  19. #define BetaRelease (0x60)
  20. #define FinalRelease (0x80)
  21. #define DevelopmentStringID (0x00800004)
  22. #define AlphaStringID (0x00800005)
  23. #define BetaStringID (0x00800006)
  24. #define NonFinalLocID (0x00800005)
  25.  
  26.  
  27. /* */            CAboutWindow::~CAboutWindow()
  28.     {
  29.         DeregisterIdler(this);
  30.         Application->AboutWindow = NIL; /* indicate we are gone */
  31.     }
  32.  
  33.  
  34. void            CAboutWindow::IAboutWindow(MyBoolean TheAutoFlag)
  35.     {
  36.         LongPoint                            Start;
  37.         LongPoint                            Extent;
  38.         CAboutWindowPicture*    AboutWindowPicture;
  39.  
  40.         GetRect(AboutWindowLocationID,&Start,&Extent);
  41.         IWindow(CenterRect(Extent,LongPointOf(screenBits.bounds.right
  42.             - screenBits.bounds.left,screenBits.bounds.bottom - screenBits.bounds.top)),
  43.             Extent,ModelessWindow,NoGrowable,NoZoomable);
  44.         if (TheAutoFlag)
  45.             {
  46.                 RegisterIdler(this,60);
  47.             }
  48.         AboutWindowPicture = new CAboutWindowPicture;
  49.         AboutWindowPicture->IAboutWindowPicture(this);
  50.         MomentOfInstantiation = TickCount();
  51.         AutoFlag = TheAutoFlag;
  52.         BecomeActiveWindow();
  53.     }
  54.  
  55.  
  56. void            CAboutWindow::DoIdle(long TimeSinceLastEvent)
  57.     {
  58.         if (AutoFlag)
  59.             {
  60.                 if (TickCount()-MomentOfInstantiation > ShowDelay)
  61.                     {
  62.                         GoAway();
  63.                         return;
  64.                     }
  65.             }
  66.         inherited::DoIdle(TimeSinceLastEvent);
  67.     }
  68.  
  69.  
  70. void            CAboutWindow::GoAway(void)
  71.     {
  72.         delete this;
  73.     }
  74.  
  75.  
  76. MyBoolean    CAboutWindow::DoMenuCommand(ushort MenuCommandValue)
  77.     {
  78.         if (MenuCommandValue == mFileClose)
  79.             {
  80.                 GoAway();
  81.                 return True;
  82.             }
  83.         return Application->DoMenuCommand(MenuCommandValue);
  84.     }
  85.  
  86.  
  87. void            CAboutWindow::EnableMenuItems(void)
  88.     {
  89.         MyEnableItem(mFileClose);
  90.         Application->EnableMenuItems();
  91.     }
  92.  
  93.  
  94. /********************************************************************************/
  95.  
  96.  
  97. void        CAboutWindowPicture::IAboutWindowPicture(CWindow* TheWindow)
  98.     {
  99.         LongPoint        Start;
  100.         LongPoint        Extent;
  101.  
  102.         GetRect(PictureLocationID,&Start,&Extent);
  103.         IViewRect(ZeroPoint,Extent,TheWindow,TheWindow);
  104.     }
  105.  
  106.  
  107. void        CAboutWindowPicture::DoUpdate(void)
  108.     {
  109.         PicHandle        Image;
  110.         Handle            Text;
  111.         Handle            VersRes;
  112.         Handle            Text2;
  113.         Handle            Text3;
  114.         LongPoint        VersLocStart;
  115.         LongPoint        VersLocExtent;
  116.         LongPoint        VBoxLocStart;
  117.         LongPoint        VBoxLocExtent;
  118.         short                ReleaseType;
  119.         short                NonReleaseVersion;
  120.  
  121.         ERROR(ResLoad == 0,PRERR(ForceAbort,"Automatic resource loading is disabled."));
  122.         SetUpPort();
  123.         Image = (PicHandle)GetResource('∫Cpc',PictureID);
  124.         ERROR(Image==NIL,PRERR(ForceAbort,"∫Cpc image resource not present."));
  125.         ERROR(ResErr != noErr,PRERR(ForceAbort,"Resource Error occurred."));
  126.         Window->LDrawPicture(Image,ZeroPoint,Extent);
  127.         ReleaseResource((Handle)Image);
  128.         Window->SetText(GetFontID("\pGeneva"),0,srcOr,9,0);
  129.         VersRes = GetResource('vers',1); /* get application version information */
  130.         ERROR(ResErr != noErr,PRERR(ForceAbort,"Resource Error occurred."));
  131.         HLock(VersRes);
  132.         ReleaseType = (*(uchar**)VersRes)[2]; /* pluck out release type */
  133.         NonReleaseVersion = ((*(uchar**)VersRes)[3] & 0x0f)
  134.             + 10*(((*(uchar**)VersRes)[3] & 0xf0) >> 4); /* pluck out non release version */
  135.         ERROR(VersRes==NIL,PRERR(ForceAbort,
  136.             "CImagePane::DoUpdate couldn't find 'vers' 1 resource."));
  137.         Text = PString2Handle(&(((uchar*)*VersRes)[6])); /* extract version string */
  138.         HUnlock(VersRes);
  139.         ReleaseResource(VersRes);
  140.         Text2 = GetCString(ApplicationVersionStringID); /* get "Version " */
  141.         Text3 = HStrCat(Text2,Text);
  142.         ReleaseHandle(Text);
  143.         ReleaseHandle(Text2); /* get rid of original handles */
  144.         GetRect(ApplicationVersionLocationID,&VersLocStart,&VersLocExtent);
  145.         VBoxLocStart.x = VersLocStart.x - 4;
  146.         VBoxLocStart.y = VersLocStart.y - 4;
  147.         VBoxLocExtent.x = VersLocExtent.x + 8;
  148.         VBoxLocExtent.y = VersLocExtent.y + 8;
  149.         Window->LEraseRect(VBoxLocStart,VBoxLocExtent);
  150.         Window->LTextBox(VersLocStart,VersLocExtent,Text3,JustifyLeft);
  151.         Window->LFrameRect(VBoxLocStart,VBoxLocExtent);
  152.         ReleaseHandle(Text3);
  153.         if (ReleaseType != FinalRelease)
  154.             {
  155.                 switch (ReleaseType)
  156.                     {
  157.                         case DevelopmentRelease:
  158.                             Text = GetCString(DevelopmentStringID);
  159.                             break;
  160.                         case AlphaRelease:
  161.                             Text = GetCString(AlphaStringID);
  162.                             break;
  163.                         case BetaRelease:
  164.                             Text = GetCString(BetaStringID);
  165.                             break;
  166.                         default:
  167.                             PRERR(ForceAbort,"Invalid version resource.");
  168.                     }
  169.                 Text2 = Int2String(NonReleaseVersion);
  170.                 Text3 = HStrCat(Text,Text2);
  171.                 ReleaseHandle(Text);
  172.                 ReleaseHandle(Text2);
  173.                 GetRect(NonFinalLocID,&VersLocStart,&VersLocExtent);
  174.                 VBoxLocStart.x = VersLocStart.x - 4;
  175.                 VBoxLocStart.y = VersLocStart.y - 4;
  176.                 VBoxLocExtent.x = VersLocExtent.x + 8;
  177.                 VBoxLocExtent.y = VersLocExtent.y + 8;
  178.                 Window->LEraseRect(VBoxLocStart,VBoxLocExtent);
  179.                 Window->LTextBox(VersLocStart,VersLocExtent,Text3,JustifyLeft);
  180.                 Window->LFrameRect(VBoxLocStart,VBoxLocExtent);
  181.                 ReleaseHandle(Text3);
  182.             }
  183.     }
  184.